<template>
  <el-container>
    <el-header>
      <div class="logo">
        涛帅考试
      </div>
      <div class="user-info">
        <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"></el-avatar>
        <el-dropdown>
          <span>
            {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-menu
          background-color="#2F3447"
          text-color="#fff"
          active-text-color="#fff"
          :default-active="$route.path"
          router>
          <el-menu-item index="/home/user" v-if="userInfo.role == 'ROLE_admin'">
            <i class="el-icon-setting"></i>
            <span slot="title">用户管理</span>
          </el-menu-item>
          <el-submenu index="/home/problem" v-if="userInfo.role == 'ROLE_admin'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>题目管理</span>
            </template>
            <el-menu-item index="/home/problem/add">
              <i class="el-icon-menu"></i>
              <span slot="title">添加题目</span>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="/home/exam" v-if="userInfo.role == 'ROLE_admin'">
            <template slot="title">
              <i class="el-icon-menu"></i>
              <span>考试管理</span>
            </template>
            <el-menu-item index="/home/exam/add">
              <i class="el-icon-menu"></i>
              <span slot="title">创建考试</span>
            </el-menu-item>
            <el-menu-item index="/home/exam/list">
              <i class="el-icon-menu"></i>
              <span slot="title">考试列表</span>
            </el-menu-item>
          </el-submenu>
          <el-menu-item index="/home/myExam" v-if="userInfo.role == 'ROLE_user'">
            <i class="el-icon-setting"></i>
            <span slot="title">我的考试</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-main>
        <vab-breadcrumb></vab-breadcrumb>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import VabBreadcrumb from '../VabBreadcrumb/index'
  import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'
  export default {
    components: { VabBreadcrumb },
    data() {
      return {
        user: {
          username: 'admin',
        }
      }
    },
    methods: {
      logout() {
        this.$store.commit('saveUserInfo', {})
        this.$router.push("/");
      }
    },
    computed:{
      ...mapGetters([
        'userInfo',
      ]),
    }
  }
</script>

<style lang="scss" scoped>


  .el-container {
    overflow: hidden;
    height: 100%;
    .el-header {
      border-bottom: 1px solid #eee;
      width: 100vw;
      padding: 0 160px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .logo {
        font-size: 20px;
        line-height: 30px;
        color: black;
        width: 100px;

      }
      .user-info {
        display: flex;
        align-items: center;
        .el-avatar{
          margin-right: 5px;
        }
        .el-dropdown {
          cursor: pointer;
        }
      }
    }
    .el-container{
      .el-aside{
        height: 100%;
        background-color: #2F3447;
        .el-menu-item {
          &:hover {
            background-color: #41B584 !important;
          }
        }
        .el-menu-item.is-active{
          background-color: #41B584 !important;
        }
      }
      .el-main{
        padding-top: 0;
        background-color: #F6F8F9;
        padding-left: 60px;
        height: 100%;
        >.el-card{
          padding-top: 20px;
        }
      }
    }



  }
</style>
